<template>
	<div>
		<div class="jumbotron">
			<form class="form-horizontal" role="form" @submit.prevent="">
				<div class="form-group">
					<div class="col-sm-offset-2 col-sm-10">
						<h1>职位管理</h1>
					</div>
				</div>
				<div class="col-sm-2"></div>
				<div class="form-group table-responsive col-sm-8">
					<table class="table">
						<thead align="right">
							<tr>
								<th>职位名称</th>
								<th>工作地点</th>
								<th>职位描述</th>
								<th>月薪</th>
								<th>被投递次数</th>
								<th>职位TAG</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="item in jobInfo">
								<td>{{item.jobName}}</td>
								<td>{{item.region}}</td>
								<td>{{item.jobDescrip}}</td>
								<td>{{item.salaryMin===0&&item.salaryMax===0?"面议":item.salaryMin+"~"+item.salaryMax}}</td>
								<td>{{item.postedNum}}</td>
								<td>
								{{(JSON.stringify(JSON.parse(item.tag)).replace(/\"/g,"").replace("["," ").replace("]"," ").replace(/ /g,"")==="")
								?"无"
								:JSON.stringify(JSON.parse(item.tag)).replace(/\"/g,"").replace("["," ").replace("]"," ").replace(/,/g," / ")}}
								</td>
								<td v-if="item.verified==='0'">
									<button type="button" class="btn btn-primary" @click="auditItem(item)">通过审核</button>
									<button type="button" class="btn btn-danger" @click="deleteItem(item)">删除信息</button>
								</td>
								<td v-else>
									<button type="button" class="btn btn-danger" @click="deleteItem(item)">删除信息</button>
								</td>
							</tr>
						</tbody>
					</table>
				</div>
			</form>
		</div>
	</div>
</template>

<script>
	module.exports = {
		mounted() {
		    if(localStorage.getItem("sysUser").trim()===""||localStorage.getItem("sysUser").trim()==="undefined"||localStorage.getItem("sysUser").trim()==="null"){

		    }else{
		    $.ajax({
            				url: conf.ur + "/api/enterprise/listAllJob?holderId=" + JSON.parse(localStorage.getItem("sysUser")).id,
            				type: 'get',
            				dataType: 'json',
            				headers: {
            					"x-auth-token": window.localStorage.getItem('x-auth-token')
            				},
            				success: (data) => {
            					console.log(data)
            					if (data.code === 0) {
            						this.jobInfo = data.data;
            					} else {
            						console.log("获取失败！")
            					}
            				},
            				error: (err) => {
            					console.log("网络异常！")
            					conf.storage.clear();
            					window.location.reload();
            				}
            			});
		    }
		},
		data: function() {
			return {
				jobInfo: [],
				userID: '',
			}
		},
		methods: {
			deleteItem(item) {
				if (confirm("确认删除此职位信息吗？") == true) {
					$.ajax({
						url: conf.ur + "/api/enterprise/deleteJob?id=" + item.id,
						type: 'get',
						headers: {
							"Content-Type": "application/json",
							"x-auth-token": window.localStorage.getItem('x-auth-token')
						},
						success: (data) => {
							if (data.code === 0) {
								alert("删除成功！");
								window.location.reload();
							} else {
								alert("删除失败！")
								window.location.reload();
							}
						},
						error: (err) => {
							console.log("网络异常！")
						}
					});
				}
			},
		}
	}
</script>

<style scoped>
	.goodsImg {
		height: 100px;
	}

	.jumbotron {
		background-color: ghostwhite;
	}
</style>
